<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        html body {
            height: 100%;
            width: 100%;
        }

        ul {
            width: 100%;
            padding-top: 33px;
            /* padding: 20px 0; */
            /* box-sizing: border-box; */
            display: flex;
            flex-wrap: wrap;
            justify-content: space-evenly;
            align-items: center;
        }

        li {
            width: 40%;
            height: 200px;
            background-color: pink;
            margin-bottom: 20px;
        }

        img {
            width: 100%;
            height: 100%;
        }
    </style>
</head>

<body>
    <!--  -->
    <ul>
        <li><img src="" alt=""></li>
        <li><img src="" alt=""></li>
        <li><img src="" alt=""></li>
        <li><img src="" alt=""></li>
        <li><img src="" alt=""></li>
        <li><img src="" alt=""></li>
        <li><img src="" alt=""></li>
        <li><img src="" alt=""></li>
        <li><img src="" alt=""></li>
        <li><img src="" alt=""></li>
        <li><img src="" alt=""></li>
        <li><img src="" alt=""></li>
        <li><img src="" alt=""></li>
        <li><img src="" alt=""></li>
        <li><img src="" alt=""></li>
        <li><img src="" alt=""></li>

    </ul>
    <script>
        const imgs = document.querySelectorAll("li>img")
        function isInViewPortOfOne(el) {

            const viewPortHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight
            const offsetTop = el.offsetTop
            const scrollTop = document.documentElement.scrollTop
            const top = offsetTop - scrollTop
            return top <= viewPortHeight
        }


        function fn() {
            imgs.forEach((item) => {
                let juli = item.offsetTop
                let res = isInViewPortOfOne(item)
                if (res) {
                    item.src = "./images/1.jpg"
                }

            })
        }
        fn()


        window.addEventListener("wheel", function (e) {
            let evt = e || window.event;  //考虑兼容性
            // evt.preventDefault();
            if (evt.deltaY > 0) {  //在火狐中 向下滚动是3 谷歌是125
                fn()
            } else {           //在火狐中 向上滚动是-3 谷歌是-125
                console.log("向上滚动");
            }
            //检查事件
            console.log(evt.type, evt.deltaX, evt.deltaY, evt.deltaZ);
        }, {
            passive: false
        });




        let scroolJuli = document.documentElement.scrollTop
        console.log(scroolJuli, "+++++++");


    </script>
</body>

</html>